﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Easy.Common;
using Easy.BLL;
using Easy.Operation;

namespace Easy.Web.Service.Data
{
    /// <summary>
    /// AssignOwningUser 的摘要说明
    /// </summary>
    public class AssignOwningUser : BaseHttpHandler
    {

        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Guid OwningUserId = Guid.Empty;
            Guid TargetId = Guid.Empty;
            CustomResult rc = new CustomResult();
            string EntityName = context.Request["entityname"];
            try
            {
                if (EntityName == null) throw new Exception();
                TargetId = new Guid(context.Request["targetid"]);
                OwningUserId = new Guid(context.Request["owninguserid"]);
            }
            catch (Exception)
            {
                rc.ResultMessage = "参数错误或不完整";
                rc.ResultCode = 1;
                context.Response.Write(JsonConvert.SerializeObject(rc));
                return;
            }
            DataService dataService = new DataService(EntityName, CurrentUserId);
            try
            {
                dataService.Assign(TargetId, OwningUserId);
                rc.ResultMessage = "成功";
                rc.ResultCode = 0;
            }
            catch (Exception e)
            {
                rc.ResultMessage = e.Message;
                rc.ResultCode = 1;
            }
            context.Response.Write(JsonConvert.SerializeObject(rc));
        }
    }
}